﻿import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 2.12
import QtMultimedia 5.14

Window {
    title: "新建"
    width: 700*dp
    height: 610*dp
    property int mllx: 0
    property int ind: 0
    property var newmodel: []
    property string bhv: ""
    property string mcv: ""
    property string lxv: ""
    property string njv: ""
    property string njgcv: ""
    property string qswzv: ""
    property string jsbv: ""
    property string dcv: ""
    property string qbv: ""
    property string bsv: ""
    property string zbsv: ""
    property string sdv: ""
    property string dwv: ""
    signal newmo(int ind,var newmodel)
    onVisibleChanged: {
        if(mllx===1){
            bh.setText(bhv)
            mc.setText(mcv)
            lx.setText(lxv)
            nj.setText(njv)
            njgc.setText(njgcv)
            qswz.setText(qswzv)
            jsb.setText(jsbv)
            dc.setText(dcv)
            qb.setText(qbv)
            bs.setText(bsv)
            zbs.setText(zbsv)
            zsqsd.setText(sdv)
            zsqdw.setText(dwv)
        }else{
            bh.setIndex(0)
            mc.setText("")
            lx.setIndex(0)
            nj.setText("")
            njgc.setText("")
            qswz.setText("")
            jsb.setIndex(0)
            qb.setText("800")
            dc.setText("0.6096")
            zsqsd.setText("")
            zsqdw.setIndex(0)
        }
        lx.model=CExeConfig.getzsqdef()


    }
    Toast{
        id: toast
        y: 80*dp
        x: parent.width / 2 - 150*dp
        z: 1
    }

    PushButton{
        y:20*dp
        x:parent.width-530*dp
        defaultMode1: true
        title: "复位原点"
        onReleased: {
            CMaintenance.resetSyring(bh.getText())
        }
    }

    PushButton{
        y:20*dp
        x:parent.width-400*dp
        defaultMode1: true
        title: "执行"
        onReleased: {
            if(dc.getText()===""){
                toast.show("请输入导程",1)
            }else{
                CMaintenance.runningSyring(hcna,bh.getText(),bs.getText(),zbs.getText())
            }


        }
    }
    PushButton{
        y:20*dp
        x:parent.width-270*dp
        defaultMode1: true
        title: "保存"
        onReleased: {
            if(nj.getText()===""||njgc.getText()===""||qswz.getText()===""||zsqsd.getText()===""||dc.getText()===""){
                toast.show("请确认参数是否填写完整",1)
            }else{
                newmo(ind,[bh.getText(),mc.getText(),lx.getText(),nj.getText(),njgc.getText(),qswz.getText(),jsb.getText(),
                      dc.getText(),qb.getText(),bs.getText(),zbs.getText(),zsqsd.getText(),zsqdw.getText()])
                close()
            }


        }
    }
    PushButton{
        y:20*dp
        x:parent.width-140*dp
        text_color: "black"
        button_color: "#FF9478"
        button_border : "transparent"
        button_color_press : "#FF9400"
        title: "停止"
        onReleased: {
            CMaintenance.stopSyring(bh.getText())
        }
    }
    CustomComboBox{
        id:bh
        title: qsTr("编号")
        width: 260*dp
        x:20*dp
        y:80*dp
        titleWidth: 100*dp
        editWidth: 160*dp
        model:["1","2","3","4","5","6"]
    }
    CustomInputText{
        id:mc
        title: "名称"
        width: 260*dp
        x:400*dp
        y:80*dp
        titleWidth: 100*dp
        editWidth: 160*dp
    }
    CustomComboBox{
        id:lx
        title:qsTr("类型")
        x:20*dp
        y:140*dp
        width: 260*dp
        titleWidth: 100*dp
        editWidth: 160*dp
        model: CExeConfig.getzsqdef()
    }
    CustomInputText{
        id:nj
        title: qsTr("<font color='red'>*</font>内径(mm)")
        width: 260*dp
        x:400*dp
        y:140*dp
        titleWidth: 100*dp
        editWidth: 160*dp
    }
    CustomInputText{
        id:njgc
        title: qsTr("<font color='red'>*</font>内径公差(mm)")
        width: 260*dp
        x:20*dp
        y:200*dp
        titleWidth: 100*dp
        editWidth: 160*dp
    }
    CustomInputText{
        id:qswz
        title: qsTr("<font color='red'>*</font>起始位置(mm)")
        width: 260*dp
        x:400*dp
        y:200*dp
        titleWidth: 100*dp
        editWidth: 160*dp
        onTextChanged: {
            if(zsqdw.getText()==="mL/Min"){
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }else{
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }
        }
    }
    CustomInputText{
        id:zsqsd
        x:20*dp
        y:260*dp
        title: qsTr("<font color='red'>*</font>电机速度")
        width: 200*dp
        titleWidth: 100*dp
        editWidth: 100*dp
    }
    CustomComboBox{
        id:zsqdw
        x:230*dp
        y:260*dp
        width: 100*dp
        editWidth: 100*dp
        titleWidth: 0*dp
        model: ["mL/Min","mm/s"]
        onCurrentText: {
            if(zsqsd.getText()===""){
                return
            }

            zsqsd.setText(GetMessageInterface.unitConversion(zsqsd.getText(),nj.getText(),zsqdw.getText()))
        }
    }
    Text {
        x:665*dp
        y:210*dp
        color: "#1677FF"
        text: qsTr("获取")
        font.pixelSize: text_size
        MouseArea{
            anchors.fill:parent
            cursorShape: "PointingHandCursor"
            onReleased: {
                qswz.setText(CMaintenance.readPos(bh.getText()))
            }
        }
    }
    Rectangle{
        x:20*dp
        y:340*dp
        width: parent.width-40*dp
        height: 1*dp
        color: "#B8B7B5"
    }
    Text {
        x:20*dp
        y:350*dp
        text: qsTr("电机配置")
        font.bold: true
        font.pixelSize: config.pointsize + 2*dp
    }
    CustomComboBox{
        id:jsb
        title: "减速比"
        width: 260*dp
        x:20*dp
        y:410*dp
        titleWidth: 100*dp
        editWidth: 160*dp
        model:["1:1","1:2","1:3","1:4","1:5","1:6","1:7","1:8","1:9","1:10",
            "1:11","1:12","1:13","1:14","1:15","1:16","1:17","1:18","1:19","1:20"]
        onCurrentText: {
            if(zsqdw.getText()==="mL/Min"){
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }else{
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }
        }
    }
    CustomInputText{
        id:dc
        title: qsTr("<font color='red'>*</font>导程(圈/毫米)")
        width: 260*dp
        x:400*dp
        y:410*dp
        titleWidth: 100*dp
        editWidth: 160*dp
        onTextChanged: {
            if(zsqdw.getText()==="mL/Min"){
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }else{
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }
        }
    }
    CustomComboBox{
        id:qb
        title: "圈步"
        width: 260*dp
        x:20*dp
        y:470*dp
        titleWidth: 100*dp
        editWidth: 160*dp
        model:["3200"]
        onCurrentText: {
            if(zsqdw.getText()==="mL/Min"){
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),nj.getText(),jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }else{
                bs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[0])
                zbs.setText(CMaintenance.calculateSteps(zsqsd.getText(),"",jsb.getText(),dc.getText(),qb.getText(),qswz.getText())[1])
            }
        }
    }
    CustomInputText{
        id:bs
        title: "步数(步/秒)"
        width: 260*dp
        editable: false
        x:400*dp
        y:470*dp
        titleWidth: 100*dp
        editWidth: 160*dp
    }
    CustomInputText{
        id:zbs
        title: "总步数"
        width: 260*dp
        editable: false
        x:20*dp
        y:530*dp
        titleWidth: 100*dp
        editWidth: 160*dp
    }


}
